<template>
	<div class="app-container">
		<el-form class="search-form">
			<el-form-item class="form-button-bar">
				<el-button @click="newTheme" type="success">新增主题</el-button>
				<el-button @click="handleDeleteList" type="danger">归档主题</el-button>
				<el-button @click="addHotList" type="warning">加入热点</el-button>
	        	<el-button plain class="search-bar-button" style="float: right;border-width: 2px" type="primary" @click="searchBarVisable = !searchBarVisable">{{searchBarVisable?'收起':'展开'}}搜索项<i :class="searchBarVisable?'el-icon-caret-top':'el-icon-caret-bottom'"></i></el-button>
			</el-form-item>
		</el-form>
		<el-form class="search-form" label-width="80px">
			<div :class="searchBarVisable?'':'search-bar-hide'" style="transition:  all .3s ease-in-out;">
				<el-form-item label="主题名称" prop="topicName">
					<el-input style="width: 450px;" clearable v-model.trim="listQuery.topicName" placeholder="请输入"></el-input>
				</el-form-item>
				<el-form-item label="核心标签" prop="keyword">
					<el-select v-model="listQuery.keyword" filterable clearable placeholder="请选择" style="width: 450px;">
						<el-option v-for="item in tagOptions" :key="item.keyword" :label="item.keyword" :value="item.keyword"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="主题状态">
					<el-radio v-model="listQuery.topicStatus" label="" border size="mini">全部</el-radio>
					<el-radio v-model="listQuery.topicStatus" label="0" border size="mini">正常</el-radio>
					<el-radio v-model="listQuery.topicStatus" label="1" border size="mini">已归档</el-radio>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" @click="getList">{{$t('table.search')}}</el-button>
				</el-form-item>
			</div>
		</el-form>
		<el-table :data="list" v-loading="listLoading" element-loading-text="加载中..." border fit highlight-current-row @selection-change="handleSelectionChange" style="width: 100%">
			<el-table-column align="center" type="selection" width="55"></el-table-column>
      <el-table-column align="center" label="主题名称" min-width="100">
      	<template slot-scope="scope">
      		<el-button class="preview-button" type="text" @click="handleShow(scope.row, 'show')">{{scope.row.topicName}}</el-button>
      	</template>
      </el-table-column>
			<el-table-column label="事件" align="center" min-width="200">
				<template slot-scope="scope">
					<p v-for="(item, index) in scope.row.topicEvents" style="text-align: left;">{{ index + 1 }}.{{ item.eventTitle }}</p>
				</template>
			</el-table-column>
			<el-table-column label="核心标签" align="center" width="80">
				<template slot-scope="scope">
					<el-tag size="small">{{ scope.row.keyword }}</el-tag>
				</template>
			</el-table-column>
			<el-table-column align="center" label="审核状态" width="80">
				<template slot-scope="scope">
					<el-tag size="small" :type="checkClass(scope.row.auditStatus)">{{checkStatu(scope.row.auditStatus)}}</el-tag>
				</template>
			</el-table-column>
			<el-table-column prop="updater" label="审核人" align="center"></el-table-column>
			<el-table-column prop="createTime" label="创建时间" align="center" width="100"></el-table-column>
			<el-table-column prop="updateTime" label="更新时间" align="center" width="100"></el-table-column>
			<el-table-column align="center" label="主题状态">
				<template slot-scope="scope">
					<el-tag size="small" :type="formatClass(scope.row.topicStatus)">{{formatStatu(scope.row.topicStatus)}}</el-tag>
				</template>
			</el-table-column>
			<el-table-column prop="topicHot" label="热度" align="center"></el-table-column>
			<el-table-column label="是否加入热点" align="center" width="105">
				<template slot-scope="scope">
					<span v-if="scope.row.isHot == 1">是</span>
					<span v-else>否</span>
				</template>
			</el-table-column>
			<el-table-column label="操作" align="center" width="242">
				<template slot-scope="scope">
					<el-button size="mini" @click="handleShow(scope.row, 'update')" v-if='scope.row.topicStatus == 0'>编辑</el-button>
					<el-button size="mini" type="danger" @click="handleDelete(scope.row)" v-if='scope.row.topicStatus == 0' :disabled="scope.row.isHot == 1 || scope.row.auditStatus == 0">归档</el-button>
					<el-button size="mini" type="warning" @click="addHot(scope.row)" v-if='scope.row.topicStatus == 0' :disabled="scope.row.isHot == 1 || scope.row.auditStatus == 0">加入热点</el-button>
					<el-button size="mini" type="danger" @click="dataStatusChange(scope.row)" v-else>取消归档</el-button>
				</template>
			</el-table-column>
		</el-table>
		<div class="pagination-container">
			<el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.pageNum" :page-sizes="[10, 20, 30, 50]" :page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
		</div>
		<el-dialog :fullscreen='true' :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
			<el-form ref="temp" :model="temp" :rules="editRules" label-position="left" label-width="130px" style='margin: auto; max-width: 1200px'>
				<el-row :gutter="24">
					<el-col :span="10">
						<el-form-item label="主题名称" prop="topicName">
							<el-input v-model.trim="temp.topicName" type="text" placeholder="请输入" :disabled="dialogStatus == 'show'"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="10">
						<el-form-item label="审核管理" prop="adjustModel">
							<el-select v-model="temp.adjustModel" placeholder="请选择" :disabled="dialogStatus == 'show'">
								<el-option label="自动审核" :value='1'></el-option>
								<el-option label="手动审核" :value="0"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="10">
						<el-form-item label="核心标签" prop="keyword">
							<el-select :disabled="dialogStatus !== 'create'"  v-model="temp.keyword" filterable value-key='keyword' placeholder="请选择" @change="selectShange">
								<el-option v-for="(item, index) in tagOptions" :key="item.keyword" :label="item.keyword" :value="item">
									<span style="float: left">{{ item.keyword }}</span>
									<span style="float: right; color: #8492a6; font-size: 13px">{{ item.num }}</span>
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="10">
						<el-form-item label="主题热度" prop="topicHot">
							<el-input disabled v-model="temp.topicHot" placeholder="请选择核心标签"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="4" v-if="dialogStatus !== 'show'">
						<el-button type="warning" @click="getMessage('temp')">生成主题内容</el-button>
					</el-col>
          <el-col :span="24">
          	<el-form-item label="主题描述" prop="descript">
          		<el-input v-model="temp.descript" type="textarea" :rows="3" :maxlength='200' placeholder="请输入" :disabled="dialogStatus == 'show'"></el-input>
          	</el-form-item>
          </el-col>
					<el-col :span="24">
						<el-form-item label="事件驱动">
							<el-button v-if="dialogStatus !== 'show'" style="float: right;" @click="evtDelete(temp.topicEvents)" type="text">批量删除</el-button>
							<el-table v-loading="tagLoading" element-loading-text="加载中..." stripe max-height="500" :data="temp.topicEvents" style="width: 100%" border fit highlight-current-row @selection-change="evtSelect">
								<el-table-column v-if="dialogStatus !== 'show'" align="center" type="selection" width="55" key="1"></el-table-column>
								<el-table-column prop="createTime" label="发生时间" align="center" width="100"></el-table-column>
								<!--<el-table-column prop="eventTitle" label="事件名称" align="center" min-width="200"></el-table-column>-->
								<el-table-column label="事件名称" align="center" min-width="100">
							        <template slot-scope="scope">
							          	<el-button class="preview-button" type="text" @click="eventInfo(scope.row)">{{ scope.row.eventTitle }}</el-button>
							        </template>
								</el-table-column>
								<el-table-column label="事件标签" align="center" min-width="150">
									<template slot-scope="scope">
										<el-tag v-for="(tag, index) in scope.row.lisTags" :key="tag.keyword">{{ tag.keyword }}</el-tag>
									</template>
								</el-table-column>
								<el-table-column prop="eventDescript" label="事件描述" align="center" show-overflow-tooltip></el-table-column>
								<el-table-column label="操作" align="center" width="150" v-if="dialogStatus !== 'show'" key="2">
									<template slot-scope="scope">
										<el-button size="mini" type="danger" @click="deleteRow(scope.$index, temp.topicEvents)">删除</el-button>
									</template>
								</el-table-column>
							</el-table>
						</el-form-item>
					</el-col>
					<el-col :span="24" v-if="dialogStatus !== 'create'">
						<el-form-item label="历史新闻">
							<el-table v-loading="infoScLoading" stripe max-height="500" :data="temp.listNewsInfoSc" style="width: 100%" border fit highlight-current-row>
								<el-table-column type="index" width="40" align="center"></el-table-column>
								<el-table-column label="标题" align="center" min-width="200">
				                  	<template slot-scope="scope">
				                  		<el-button class="preview-button" type="text" @click="showInfo(scope.row)">{{scope.row.title}}</el-button>
				                  	</template>
	            				</el-table-column>
								<el-table-column prop="summary" label="摘要" align="center" min-width="300"></el-table-column>
								<el-table-column prop="createTime" label="创建时间" align="center" width="100"></el-table-column>
								<el-table-column prop="updateTime" label="更新时间" align="center" width="100"></el-table-column>
								<el-table-column prop="source" label="来源" align="center"></el-table-column>
								<el-table-column label="态度" align="center" width="65">
									<template slot-scope="scope">
										<span v-if="scope.row.attitude == -1" class="tagColor" style="background-color: #4cba2a;">&nbsp;利空&nbsp;</span>
										<span v-else-if="scope.row.attitude == 0" class="tagColor" style="background-color: #c5d106;">&nbsp;中性&nbsp;</span>
										<span v-else="scope.row.attitude == 1" class="tagColor" style="background-color: red;">&nbsp;利好&nbsp;</span>
									</template>
								</el-table-column>
							</el-table>
							<div class="pagination-container" style="margin-top: 10px;">
								<el-pagination background @size-change="newsSizeChange" @current-change="newsCurrentChange" :current-page.sync="newsObj.pageNum" :page-sizes="[10, 20, 30, 50]" :page-size="newsObj.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="newsTotal"></el-pagination>
							</div>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="相关股票">
							<div style="float: right;" v-if="dialogStatus !== 'show'">
								<el-button @click="stockSelect()" type="text">新增</el-button>
								<el-button @click="stockdelete(temp.topicStocks)" type="text">删除</el-button>
							</div>
							<el-table v-loading="tagLoading" element-loading-text="加载中..." stripe max-height="530" :data="temp.topicStocks" style="width: 100%" border fit highlight-current-row @selection-change="stockSlc">
								<el-table-column v-if="dialogStatus !== 'show'" align="center" type="selection" width="55" key="3"></el-table-column>
								<el-table-column prop="stockCode" label="股票代码" align="center"></el-table-column>
								<el-table-column prop="stockName" label="股票名称" align="center"></el-table-column>
								<el-table-column label="相关度" align="center">
									<template slot-scope="scope">
										<el-rate v-model="scope.row.stockSimilar" :disabled="dialogStatus == 'show'"></el-rate>
									</template>
								</el-table-column>
								<el-table-column label="龙头" align="center">
									<template slot-scope="scope">
										<el-select v-model="scope.row.isTop" type="text" placeholder="请选择" :disabled="dialogStatus == 'show'">
											<el-option label="是" :value='1'></el-option>
											<el-option label="否" :value='0'></el-option>
										</el-select>
									</template>
								</el-table-column>
								<el-table-column label="操作" align="center" width="150" v-if="dialogStatus !== 'show'" key="4">
									<template slot-scope="scope">
										<el-button size="mini" type="danger" @click="deleteRow(scope.$index, temp.topicStocks)">删除</el-button>
									</template>
								</el-table-column>
							</el-table>
						</el-form-item>
						<el-dialog append-to-body title="相关股票" :visible.sync="dialogVisible" style="text-align: center" :close-on-click-modal=false>
							<el-form-item label="查询股票" @keyup.enter.native="searchStock(stockSearch)">
								<el-input v-model="stockSearch" type="text" placeholder="请输入">
									<el-button slot="append" icon="el-icon-search" @keyup.enter.native="searchStock(stockSearch)" @click='searchStock(stockSearch)'></el-button>
								</el-input>
							</el-form-item>
							<!--<el-transfer style="text-align: left; display: inline-block" v-model="transferData" :titles="['股票列表', '已选择']" :button-texts="['移除', '添加']" :format="{noChecked: '${total}',hasChecked: '${checked}/${total}'}" :data="stockLib"></el-transfer>-->
							<el-transfer style="text-align: left; display: inline-block" v-model="transferData" :titles="['股票列表', '已选择']" :button-texts="['移除', '添加']" :format="{noChecked: '${total}',hasChecked: '${checked}/${total}'}" @change="transferChange" :data="stockLib">
							</el-transfer>
						</el-dialog>
					</el-col>
				</el-row>
				<el-dialog append-to-body title="聚合主题" :visible.sync="dialogMerge" style="text-align: center" :close-on-click-modal=false>
					<el-table :data="mergeTable" style="width: 100%" tooltip-effect="dark" border fit @selection-change="juheSelctChange">
						<el-table-column align="center" type="selection" width="55"></el-table-column>
						<!--<el-table-column label="操作" width="55">
				          	<template slot-scope="scope">
					            <el-checkbox v-model="scope.row.checked" @change="selectRadio(scope.row)"></el-checkbox>
				          	</template>
				        </el-table-column>-->
						<el-table-column prop="eventTitle" label="事件名称" align="center"></el-table-column>
						<el-table-column label="事件标签" align="center">
							<template slot-scope="scope">
								<el-tag v-for="(tag, index) in scope.row.lisTags" :key="tag.keyword">{{ tag.keyword }}</el-tag>
							</template>
						</el-table-column>
					</el-table>
					<div slot="footer" class="dialog-footer">
						<el-button @click="dialogMerge = false">取 消</el-button>
						<el-button type="primary" @click="chooseMerge">确 定</el-button>
					</div>
				</el-dialog>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="success" @click="auditMethod('temp')" v-if="dialogStatus !== 'show'">提交并审核</el-button>
				<el-button type="primary" @click="dialogFormVisible = false">关闭</el-button>
			</div>
			<el-dialog append-to-body :fullscreen='true' :title="evtInfoTitle" :visible.sync="evtDialogInfo">
				<div v-if='evtDialogInfo'>
					<evtInfoPreview :infoMsg='evtMsg' @closeFile='evtCloseFile'></evtInfoPreview>
				</div>
			</el-dialog>
			<el-dialog append-to-body :fullscreen='true' :title="infoTitle" :visible.sync="dialogInfo">
				<div v-if='dialogInfo'>
					<component :is="currentView" :infoMsg='infoMsg' @closeFile='closeFile'></component>
				</div>
			</el-dialog>
		</el-dialog>
	</div>
</template>

<script>
	import { articleStockList } from '@/api/article'
	import { themeList, coreTagGet, themeGet, evtStockGet, themeContent, themeAddInfo, themeDelete, themeEditInfo, batchHot, batchGd, newsByTheme } from '@/api/events'
	import waves from '@/directive/waves' // 水波纹指令
	import evtInfoPreview from './evtInfoPreview'
  	import intellPreview from '../project/intellPreview'
	import origPreview from '../project/origPreview'
	import roboPreview from '../project/roboPreview'

	export default {
		name: 'themeManage',
		components: {
			evtInfoPreview,
			intellPreview,
			origPreview,
			roboPreview
		},
		directives: {
			waves
		},
		watch: {
			//	    	transferData(val){
			//				this.temp.topicStocks = val.map((item, index) => {
			//	    			return {
			//	    				stockCode: item.substring(item.indexOf("(") + 1, item.indexOf(")")),
			//					 	stockName: item.split('(')[0],
			//					 	stockSimilar: item.stockSimilar || 0,
			//					 	isTop: item.isTop || 0
			//				 	}
			//				})
			//	    	}
		},
		data() {
			let tapSelect = (rule, value, callback) => {
				let arr = Object.keys(value)
				if(arr.length) {
					callback()
				} else {
					callback(new Error('请选择核心标签'))
				}
			}
			return {
				list: null,
				total: null,
				listLoading: false,
				searchBarVisable: false,
				newsTotal: null,
				newsObj: {
				    "pageSize":10,
				    "pageNum":1,
				    "id":null
				},
				infoTitle: '',
				currentView: 'intellPreview',
				tagLoading: false,
				infoScLoading: false,
				multipleSelection: [],
				multipleSelectionIds: [],
				juheSelection: [],
				dialogFormUser: false,
				dialogFormVisible: false,
				addModel: true,
				dialogStatus: '',
				dialogMerge: false,
				mergeTable: [],
				temp: {
					auditStatus: 0,
					createTime: '',
					creater: '',
					dataStatus: 0,
					id: '',
					isHot: '',
					keyword: '',
					kinds: '',
					topicName: '',
					adjustModel: 1,
					topicStatus: 0,
					topicHot: '',
          descript: '',
					topicStocks: [],
					topicEvents: [],
					updateTime: '',
					updater: ''
				},
        textMap: {
          show: '主题详情',
          update: '编辑主题',
          create: '新增主题'
        },
				listQuery: {
					pageNum: 1,
					pageSize: 20,
					topicName:'',
					keyword:'',
					topicStatus: ''
					//					isHot: 0
				},
				editRules: {
					topicName: [{
						required: true,
						message: '请输入主题名称',
						trigger: 'blur'
					}],
					keyword: [{
						required: true,
						validator: tapSelect,
						trigger: 'change'
					}]
				},
				tagOptions: [],
				currentRow: null,
				stockSearch: '',
				stockLib: [],
				transferData: [],
				evtSelection: [],
				stockSelection: [],
				dialogVisible: false,
				evtInfoTitle: '',
				evtDialogInfo: false,
		        dialogInfo: false,
		        infoMsg: {},
				evtMsg: {},
				pickerOptions: {
					shortcuts: [{
						text: '今天',
						onClick(picker) {
							const end = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1).getTime() - 1000
							const start = end + 1000 - 3600 * 1000 * 24
							picker.$emit('pick', [start, end])
						}
					}, {
						text: '最近三天',
						onClick(picker) {
							const end = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1).getTime() - 1000
							const start = end + 1000 - 3600 * 1000 * 24 * 3
							picker.$emit('pick', [start, end])
						}
					}, {
						text: '最近一周',
						onClick(picker) {
							const end = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 1).getTime() - 1000
							const start = end + 1000 - 3600 * 1000 * 24 * 7
							picker.$emit('pick', [start, end])
						}
					}]
				}
			}
		},
		created() {
			this.getList()
			coreTagGet({ keyword: '' }).then(res => {
				this.tagOptions = Object.assign([], res.Data)
			})
		},
		methods: {
			getList() {
				this.listLoading = true
				const params = Object.assign({}, this.listQuery)
				themeList(params).then(res => {
					this.listLoading = false
					this.list = res.Data
					this.total = parseInt(res.total)
				})
			},
			handleSizeChange(val) {
				this.listQuery.pageSize = val
				this.getList()
			},
			handleCurrentChange(val) {
				this.listQuery.pageNum = val
				this.getList()
			},
			handleSelectionChange(val) {
				this.multipleSelection = val
				this.multipleSelectionIds = val.map(e => e.id)
			},
			juheSelctChange(val) {
				this.juheSelection = val
			},
			evtSelect(val) {
				this.evtSelection = val
			},
			stockSlc(val) {
				this.stockSelection = val
			},
			selectShange(item) {
				this.$forceUpdate() //绑定了对象（需求如此），render函数没有自动更新，数据刷新了，但是视图没有刷新
				this.tagLoading = true
				evtStockGet(item).then(res => {
					let tar = res.Data[0]
					this.temp.topicEvents = Object.assign([], tar.topicEvents)
					this.temp.topicStocks = Object.assign([], tar.topicStocks)
					this.temp.topicHot = tar.topicHot
					this.tagLoading = false
				})
				this.temp.keyword = item.keyword
			},
			handleDelete(row) {
				this.$confirm('确认归档, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					const obj = {
						kinds: 2,
						id: row.id
					}
					themeDelete(obj).then(() => {
						this.$notify({ title: '成功', message: '归档成功', type: 'success', duration: 2000 })
						this.getList()
					})
				}).catch(() => {
					this.$message({ type: 'info', message: '已取消归档' })
				})
			},
			addHotList() {
				let tar = this.multipleSelection.filter(e => e.topicStatus == 0 && e.isHot == 0)  //没归档且没加入热点
				if(tar.length === 0) {
					this.$message({ type: 'warning', message: '请勾选未加入热点的未归档主题' })
					return
				}
				this.$confirm('确认加入热点，是否继续？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let arr = tar.map(e => e.id)
	      			batchHot({ batchIds: arr }).then(() => {
						this.getList()
						this.$notify({ title: '成功', message: '加入热点成功', type: 'success', duration: 2000 })
	      			})
				}).catch(() => {
					this.$message({ type: 'info', message: '已取消加入热点' })
				})
			},
			handleDeleteList() {
				let tar = this.multipleSelection.filter(e => e.auditStatus == 1 && e.isHot == 0) //已审核且没加入热点
				if (tar.length === 0) {
					this.$message({ type: 'warning', message: '请勾选已审核且未加入热点的主题进行归档' })
					return
				}
				this.$confirm('确认归档，是否继续？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let arr = tar.map(e => e.id)
					batchGd({
						batchIds: arr
					}).then(() => {
						this.getList()
						this.$notify({ title: '成功', message: '归档成功', type: 'success', duration: 2000 })
					})
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消归档'
					})
				})
			},
			newTheme() {
				this.temp = {
					auditStatus: 0,
					createTime: '',
					creater: '',
					dataStatus: 0,
					id: '',
					isHot: '',
					keyword: '',
					kinds: '',
					topicName: '',
					adjustModel: 1,
					topicStatus: 0,
					topicHot: '',
          descript: '',
					topicStocks: [],
					topicEvents: [],
					updateTime: '',
					updater: ''
				}
				this.dialogStatus = 'create'
				this.dialogFormVisible = true
				this.$nextTick(() => {
					this.$refs['temp'].clearValidate()
				})
			},
			getNewsList() {
				this.infoScLoading = true
				newsByTheme(this.newsObj).then(res => {
					this.temp.listNewsInfoSc = Object.assign([], res.Data)
					this.newsTotal = parseInt(res.total)
					this.infoScLoading = false
					this.$nextTick(() => {
						this.$refs['temp'].clearValidate()
					})
				})
			},
			newsSizeChange(val) {
				this.newsObj.pageSize = val
				this.getNewsList()
			},
			newsCurrentChange(val) {
				this.newsObj.pageNum = val
				this.getNewsList()
			},
			handleShow(row, str) {
				themeGet(row.id).then(res => {
					this.temp = Object.assign({}, res.Data[0])
					this.temp.listNewsInfoSc = []
					this.dialogStatus = str
					this.newsObj.id = row.id
					this.getNewsList()
					this.dialogFormVisible = true
					this.$nextTick(() => {
						this.$refs['temp'].clearValidate()
					})
				})
			},
			addRadioChange(val) {
				if(val) return this.addModel = false
				this.addModel = true
			},
			addHot(row) {
				this.$confirm('确认加入热点, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					let obj = {
						kinds: 0,
						id: row.id
					}
					themeDelete(obj).then(() => {
						this.$notify({
							title: '成功',
							message: '加入热点成功',
							type: 'success',
							duration: 2000
						})
						this.getList()
					})
				}).catch(() => {
					this.$message({
						type: 'info',
						message: '已取消加入热点'
					})
				})
			},
			dataStatusChange(row) {
				this.$confirm('确认取消归档, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					const obj = {
						kinds: 3,
						id: row.id
					}
					themeDelete(obj).then(() => {
						this.$notify({ title: '成功', message: '取消归档成功', type: 'success', duration: 2000 })
						this.getList()
					})
				}).catch(() => {
					this.$message({ type: 'info', message: '已取消' })
				})
			},
			formatClass(data) {
				switch(data) {
					case 0:
						return 'success' // '正常'
					case 1:
						return 'danger' // '已归档'
				}
			},
			formatStatu(data) {
				switch(data) {
					case 0:
						return '正常'
					case 1:
						return '已归档'
				}
			},
			checkClass(data) {
				switch (data) {
					case 0:
						return 'warning' // '未审核'
					case 1:
						return 'success' // '已审核'
				}
			},
			checkStatu(data) {
				switch (data) {
					case 0:
						return '未审核'
					case 1:
						return '已审核'
				}
			},
			deleteRow(index, rows) {
				this.$confirm('确认删除, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					rows.splice(index, 1);
				}).catch(() => {
					this.$message({ type: 'info', message: '已取消删除' })
				})
			},
			stockdelete(rows) {
				if(this.stockSelection.length) {
					this.$confirm('确认删除，是否继续？', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
						this.stockSelection.forEach(item => {
							rows.forEach((val, index) => {
								if(item.stockCode == val.stockCode){
									rows.splice(index, 1);
								}
							})
						})
					}).catch(() => {
						this.$message({ type: 'info', message: '已取消删除' })
					})
				} else {
					this.$message({ type: 'warning', message: '请勾选需要删除的股票' })
					return
				}
			},
			evtDelete(rows) {
				if(this.evtSelection.length) {
					this.$confirm('确认删除，是否继续？', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
						this.evtSelection.forEach(item => {
							rows.forEach((val, index) => {
								if(item.eventId == val.eventId){
									rows.splice(index, 1);
								}
							})
						})
					}).catch(() => {
						this.$message({ type: 'info', message: '已取消删除' })
					})
				} else {
					this.$message({ type: 'warning', message: '请勾选需要删除的事件' })
					return
				}
			},
			stockSelect() {
				this.stockSearch = ''
				this.stockLib = this.temp.topicStocks.map(e => {
					return {
						key: e.stockName + '(' + e.stockCode + ')',
						label: e.stockName + '(' + e.stockCode + ')',
						stockSimilar: e.stockSimilar || 0,
						isTop: e.isTop || 0
					}
				})
				this.transferData = this.temp.topicStocks.map(e => {
					return e.stockName + '(' + e.stockCode + ')'
				})
				this.dialogVisible = true
			},
			transferChange(value, direction, movedKeys) { //当前值， 数据移动的方向， 发生移动的数据key数组
				if(direction == 'right') {
					movedKeys.map(tar => {
						let obj = {
							stockCode: tar.substring(tar.indexOf("(") + 1, tar.indexOf(")")),
							stockName: tar.split('(')[0],
							stockSimilar: 0,
							isTop: 0
						}
						return this.temp.topicStocks.push(obj)
					})
				} else if(direction == 'left') {
					movedKeys.forEach(val => {
						let valcode = val.substring(val.indexOf("(") + 1, val.indexOf(")"))
						this.temp.topicStocks.forEach((item, index) => {
							if(item.stockCode == valcode) {
								this.temp.topicStocks.splice(index, 1);
							}
						})
					})
				}
			},
			searchStock(e) {
				if(e.trim() === '') {
					this.$message({
						type: 'warning',
						message: '请输入有效查询内容！'
					})
					return
				}
				const params = {
					pageNum: 1,
					pageSize: 99999,
					phoneticChars: e
				}
				articleStockList(params).then(response => {
					const stocks = []
					this.stockLib = []
					this.temp.topicStocks.forEach(e => {
						stocks.push(e.stockCode)
						this.stockLib.push({
							key: e.stockName + '(' + e.stockCode + ')',
							label: e.stockName + '(' + e.stockCode + ')',
							stockSimilar: e.stockSimilar,
							isTop: e.isTop
			            })
					})
					response.Data.map(e => {
						if (stocks.indexOf(e.code) === -1) {
							if(e.name.indexOf('(') === -1){
								this.stockLib.push({
									key: e.name + '(' + e.code + ')',
									label: e.name + '(' + e.code + ')',
									stockSimilar: 0,
									isTop: 0
								})
							} else {
								let Bname = e.name.replace('(', '[')
								Bname = Bname.replace(')', ']')
								this.stockLib.push({
									key: Bname + '(' + e.code + ')',
									label: Bname + '(' + e.code + ')',
									stockSimilar: 0,
									isTop: 0
								})
							}
						}
					})
				})
			},
			auditMethod(formName) {
				this.$refs[formName].validate(valid => {
					if(valid) {
						if(this.dialogStatus == 'create') {
							const obj = Object.assign({}, this.temp)
							themeAddInfo(obj).then(res => {
								this.getList()
								this.dialogFormVisible = false
								this.$notify({ title: '成功', message: '提交成功', type: 'success', duration: 5000 })
							})
						} else if(this.dialogStatus == 'update') {
							const myObj = {
								auditStatus: 0,
								createTime: '',
								creater: '',
								dataStatus: 0,
								id: '',
								isHot: '',
								keyword: '',
								kinds: '',
								topicName: '',
								adjustModel: 1,
								topicStatus: 0,
								topicHot: '',
                descript: '',
								topicStocks: [],
								topicEvents: [],
								updateTime: '',
								updater: ''
							}
							Object.keys(myObj).forEach(val => {
								myObj[val] = this.temp[val]
							})
							themeAddInfo(myObj).then(res => {
								this.getList()
								this.dialogFormVisible = false
								this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 5000 })
							})
						}
					} else {
						console.log('error submit!!');
						return false;
					}
				})
			},
			getMessage(formName) { //核心标签必选
				this.$refs[formName].validate(valid => {
					if(valid) {
            const obj = {
              auditStatus: 0,
              createTime: '',
              creater: '',
              dataStatus: 0,
              id: '',
              isHot: '',
              keyword: '',
              kinds: '',
              topicName: '',
              adjustModel: 1,
              topicStatus: 0,
              topicHot: '',
              descript: '',
              topicStocks: [],
              topicEvents: [],
              updateTime: '',
              updater: ''
            }
            Object.keys(obj).forEach(val => {
            	obj[val] = this.temp[val]
            })
						themeContent(obj).then(res => {
							let resdata = res.Data
							if(resdata.length) {
								this.mergeTable = Object.assign([], resdata)
								this.dialogMerge = true
							} else {
								this.$message({ type: 'warning',	message: '暂无数据' })
							}
						})
					} else {
						console.log('error submit!!');
						return false;
					}
				})
			},
			selectRadio(row) {
				if(row.checked) {
					this.mergeTable.forEach(item => {
						if(item.evtName !== row.evtName) item.checked = false
					})
					this.currentRow = row
				} else {
					this.currentRow = null
				}
			},
			chooseMerge() {
				if(this.juheSelection.length) {
					this.juheSelection.forEach(item => {
						this.temp.topicEvents.push(item)
					})
					this.dialogMerge = false
				} else {
					this.$message({ type: 'warning', message: '请勾选需要聚合的数据' })
					return
				}
			},
			showInfo(row) {
				this.infoMsg = Object.assign({}, row)
				this.infoMsg.news_id = this.infoMsg.id
				if(row.isOriginal == 0){
					this.currentView = 'origPreview'
					this.infoTitle = '原创资讯详情'
				}else if(row.isOriginal == 1){
					this.currentView = 'intellPreview'
					this.infoTitle = '智能资讯详情'
				}else if(row.isOriginal == 2){
					this.currentView = 'roboPreview'
					this.infoTitle = '机器写稿详情'
				}
				this.dialogInfo = true
			},
			eventInfo(row) {
		      	this.evtMsg = Object.assign({}, row)
		      	this.evtInfoTitle = '已知事件详情'
		      	this.evtDialogInfo = true
			},
	      	closeFile() {
		      	this.dialogInfo = false
	      	},
			evtCloseFile() {
				this.evtDialogInfo = false
			}
		}
	}
</script>

<style scoped>
	.el-tag {
		margin-right: 5px;
	}
	.tagColor {
		color: white;
		border-radius: 5px;
	}
</style>
